package unl.cse.labs.lab01;

import java.util.Scanner;

public class Statistics {

	public static int getSum(int array[]) {
		if(array == null || array.length == 0){
			 return 0;
		}
		int sum =0;
		
		for(int i=0; i<array.length;i++){
			sum =sum+ array[i];
		}
		
		 return sum;
		}
		
		public static double getAverage(int array[]) {
			if(array == null || array.length < 1)
				return 0;
			int sum = getSum(array);
			return sum / (double) array.length;
		}
		
		public static int getMin(int array[]) {
			if(array == null || array.length == 0)
				return 0;
			int min = array[0];
			for(int i=1; i<array.length; i++) {
				if(array[i] < min) {
					min = array[i];
				}
			}
			return min;
		}
		
		public static int getMax(int array[]) {
			if(array == null || array.length ==0){
				 return 0;
			}
			int max=array[0];
			for(int i=1;i<array.length;i++){
				if(array[i] > max){
					max = array[i];
				}
			}
		  return max;
		}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);

		System.out.println("Please input the number of integers being entered (>=2): ");
		int n = s.nextInt();
		System.out.println(n);
		if(n < 2) {
			System.out.println("Error: please enter at least 2");
			System.exit(1);
		}
		int array[] = new int[n];
		
		for(int i=0; i<n; i++) {
			System.out.println("Enter another integer: ");
			array[i] = s.nextInt();
		}
		
		int min = Statistics.getMin(array);
		int max = Statistics.getMax(array);
		int sum = Statistics.getSum(array);
		double ave = Statistics.getAverage(array);
		
		System.out.println("The sum is " + sum);
		System.out.println("The average is " + ave);
		System.out.println("The highest is " + max);
		System.out.println("The lowest is " + min);
	}

}
